package com.example.androidautoproject.utils

import android.content.Context
import android.content.SharedPreferences

object PrefsManager {
    private const val PREFS_NAME = "AccessibilityPrefs"
    private const val KEY_PACKAGE_NAME = "target_package"
    private const val KEY_SCREEN_IDENTIFIER = "screen_identifier"
    private const val DEFAULT_PACKAGE = "com.baidu.searchbox.lite"
    private const val DEFAULT_IDENTIFIER = "com.baidu.searchbox.lite.MainActivity"
    private fun getPrefs(context: Context): SharedPreferences {
        return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
    }
    fun saveConfig(context: Context, packageName: String, screenIdentifier: String){
        getPrefs(context).edit().apply{
            putString(KEY_PACKAGE_NAME, packageName)
            putString(KEY_SCREEN_IDENTIFIER, screenIdentifier)
            apply()
        }
    }
    fun getPackageName(context: Context):String{
        return getPrefs(context).getString(KEY_PACKAGE_NAME, DEFAULT_PACKAGE) ?: DEFAULT_PACKAGE
    }
    fun getScreenIdentifier(context: Context):String{
        return getPrefs(context).getString(KEY_SCREEN_IDENTIFIER, DEFAULT_IDENTIFIER) ?: DEFAULT_IDENTIFIER
    }
}